/**
 * 地图属性
 */
import { TianDiTu } from 'mapbox-gl-utils-source';

/**
 * 默认地图初始状态
 */
export const DEFAULT_MAP_STATE = {
  key: '20668bac20071713cb3ed4bc5ca8c798',
  // 乌鲁木齐
  latitude: 44.4323,
  longitude: 85.253,
  zoom: 7,
  bearing: 0,
  pitch: 0, //倾斜度
};

/**
 * 图层组 id（顺序为自上而下，下方图层叠加在上方图层上面）
 */
export const layerGroupId = {
  RASTER_MAP: 'map',
  VECTOR: 'vector',
  RASTER_ANNOTATION: 'raster-annotation',
  VECTOR_LAYER_BASE: 'VECTOR_LAYER_BASE',
  VECTOR_LAYER2: 'VECTOR_LAYER2',
  VECTOR_LAYER1: 'VECTOR_LAYER1',
  VECTOR_LAYER: 'VECTOR_LAYER',
  MEASURE_POINT: 'MEASURE_POINT',
  MEASURE_POINT_C: 'MEASURE_POINT_C',
  MAP_POINT_LAYER: 'MAP_POINT_LAYER', //坐标点图层
  MAP_LINE_LAYER: 'MAP_LINE_LAYER', //线图层
  High_Light_RESULT_LAYER: 'High_Light_RESULT_LAYER', //高亮
  MAP_POINT_LAYER_LIGHT: 'MAP_POINT_LAYER_LIGHT',
};

/**
 * 预置数据源
 */

export const presetSource = {
  RASTER: [
    {
      _group: layerGroupId.RASTER_MAP,
      _id: 'online-tdt-raster-tiles-satellite-map',
      _title: '天地图全球卫星影像',
      _img: new URL('../assets/images/basemap/tdt-satellite.png', import.meta.url).href,

      _metadata: { serviceType: 'wmts' },
      ...TianDiTu.satellite.map({ token: DEFAULT_MAP_STATE.key }),
    },
    {
      _group: layerGroupId.RASTER_ANNOTATION,
      _id: 'online-tdt-raster-tiles-satellite-annotation',
      _title: '天地图全球卫星注记',
      _img: new URL('../assets/images/basemap/tdt-satellite-annotation.png', import.meta.url).href,

      _metadata: { serviceType: 'wmts' },
      ...TianDiTu.satellite.annotation({ token: DEFAULT_MAP_STATE.key }),
    },
  ],

  VECTOR: [],
};

/**
 * 地图相关工具
 * ! 使用多个天地图 key 进行随机调用，有配额限制
 */

export function getTDTkey() {
  const TDT_KEYS = [
    'b1e0c18fdfe387b5ab790bd060f6f6c5',
    '50f23323fd61ce53465fca366c449e87',
    '9efe144857648780afd069b42769ebe7',
    'f9540e4ba70329698cf2b10338938aa1',
    'c9f1c6dabf6aa551974969ea0a68f4df',
    '359e09124b4b02aeaf02df88f7da6689',
    '1cbdd3829c3991a80b110edbe08b91a7',
    '57afaefd3c351f564d43acfdc422799b',
  ];

  return TDT_KEYS[Math.floor(Math.random() * TDT_KEYS.length)];
}
